//
// GPSMapEdit
// (c) Konstantin Galichsky (kg@geopainting.com), 2002-2004
//
// Fast log2 calculation for integer numbers.
//

# include "StdAfx.h"
# include "fast_log2.h"

size_t fast_log2 (DWORD _dw) {
	size_t log2 = 0;
	while (_dw != 0) {
		++ log2;
		_dw >>= 1;
	}
	return log2;
}

size_t fast_log256 (DWORD _dw) {
	if (_dw == 0)
		return 0;
	else if (_dw < 256)
		return 1;
	else if (_dw < 65536)
		return 2;
	else if (_dw < 16777216)
		return 3;
	else
		return 4;
}
